package com.ruoyi.web.controller.bj;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.bj.ProductImage;
import com.ruoyi.system.service.bj.IProductImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品图片详情Controller
 * 
 * @author ruoyi
 * @date 2024-12-24
 */
@RestController
@RequestMapping("/bj/image")
public class ProductImageController extends BaseController
{
    @Autowired
    private IProductImageService productImageService;

    /**
     * 查询产品图片详情列表
     */
    @PreAuthorize("@ss.hasPermi('bj:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductImage productImage)
    {
        startPage();
        List<ProductImage> list = productImageService.selectProductImageList(productImage);
        return getDataTable(list,null);
    }

    /**
     * 导出产品图片详情列表
     */
    @PreAuthorize("@ss.hasPermi('bj:image:export')")
    @Log(title = "产品图片详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductImage productImage)
    {
        List<ProductImage> list = productImageService.selectProductImageList(productImage);
        ExcelUtil<ProductImage> util = new ExcelUtil<ProductImage>(ProductImage.class);
        util.exportExcel(response, list, "产品图片详情数据");
    }

    /**
     * 获取产品图片详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('bj:image:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productImageService.selectProductImageById(id));
    }

    /**
     * 新增产品图片详情
     */
    @PreAuthorize("@ss.hasPermi('bj:image:add')")
    @Log(title = "产品图片详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductImage productImage)
    {
        return toAjax(productImageService.insertProductImage(productImage));
    }

    /**
     * 修改产品图片详情
     */
    @PreAuthorize("@ss.hasPermi('bj:image:edit')")
    @Log(title = "产品图片详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductImage productImage)
    {
        return toAjax(productImageService.updateProductImage(productImage));
    }

    /**
     * 删除产品图片详情
     */
    @PreAuthorize("@ss.hasPermi('bj:image:remove')")
    @Log(title = "产品图片详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productImageService.deleteProductImageByIds(ids));
    }

    /**
     * 获取报价分类的的商品
     */
    @PostMapping("getProductList")
    public List<ProductImage> getProductList(@RequestParam("productImage")ProductImage productImage){
        return productImageService.selectProductImage(productImage);
    }

}
